//
//  ZqlStatusModel.swift
//  ZqlSinaWeiBo
//
//  Created by 赵乾龙 on 16/2/20.
//  Copyright © 2016年 Mr.zhao. All rights reserved.
//

import UIKit

class ZqlStatusModel: NSObject {
    
    //微博id
    var id:Int64 = 0
    
    //微博创建时间
    var created_at:String?
    
    //微博正文
    var text:String?
    
    //微博来源
    var source:String?
    
    //用户模型属性
    var user:ZqlUserInfo?
    
    //图片地址数组
    var imageUrls:[NSURL]?
    
    //转发微博属性
    var retweeted_status:ZqlStatusModel?
    
    //微博配图属性-数组
    var pic_urls:[[String:String]]?{
        didSet{
            guard let urls = pic_urls else{
                return
            }
            //实例化图片地址数组
            imageUrls = [NSURL]()
            //遍历urls数组
            for items in urls{
                let urlString = items["thumbnail_pic"]
                let str = urlString?.stringByReplacingOccurrencesOfString("thumbnail", withString: "bmiddle")
                let url = NSURL(string: str!)!
                imageUrls?.append(url)
            }
        }
    }
    
    //使用KVC设置
    init(dict:[String:AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
        
    }
    
    //对用户模型属性做字典转模型
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user"{
            if let dict = value as? [String:AnyObject]{
                user = ZqlUserInfo(dict: dict)
                return
            }
        }
        
        //对转发微博属性做字典转模型
        if key == "retweeted_status"{
            if let dict = value as? [String:AnyObject]{
                retweeted_status = ZqlStatusModel(dict: dict)
                return
            }
        }

        super.setValue(value, forKey: key)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }

}
